package cn.source.web.controller.gygl;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.system.domain.Bill;
import cn.source.system.service.IBillService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;
/**
 * 预约管理Controller
 *
 * @author gygl
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/system/bill")
@Api(value = "/bill", description = "Operations about bill")
public class BillController extends BaseController {
    @Autowired
    private IBillService billService;
    /**
     * 查询预约管理列表
     */
    @ApiOperation("查询预约管理列表")
    //@PreAuthorize("@ss.hasPermi('system:bill:list')")
    @GetMapping("/list")
    public TableDataInfo list(Bill bill) {
        startPage();
        List<Bill> list = billService.selectBillList(bill);
        return getDataTable(list);
    }
    /**
     * 导出预约管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:bill:export')")
    @Log(title = "预约管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Bill bill) {
        List<Bill> list = billService.selectBillList(bill);
        ExcelUtil<Bill> util = new ExcelUtil<Bill>(Bill.class);
        util.exportExcel(response, list, "预约管理数据");
    }
    /**
     * 获取预约管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:bill:query')")
    @GetMapping(value = "/{billId}")
    public AjaxResult getInfo(@PathVariable("billId") String billId) {
        return AjaxResult.success(billService.selectBillByBillId(billId));
    }
    /**
     * 新增预约或者住房管理
     */
    @ApiOperation(value = "新增预约或者入住管理")
    //@PreAuthorize("@ss.hasPermi('system:bill:add')")
    @Log(title = "预约管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bill bill) {
        return toAjax(billService.insertBill(bill));
    }
    /**
     * 修改预约管理
     */
//    @PreAuthorize("@ss.hasPermi('system:bill:edit')")
    @Log(title = "预约管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bill bill) {
        return toAjax(billService.updateBill(bill));
    }
    /**
     * 删除预约管理
     */
    // @PreAuthorize("@ss.hasPermi('system:bill:remove')")
    @Log(title = "预约管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{billIds}")
    public AjaxResult remove(@PathVariable String[] billIds) {
        return toAjax(billService.deleteBillByBillIds(billIds));
    }
    /**
     * 删除历史记录
     *
     * @param billId
     * @return
     */
    @ApiOperation(value = "删除历史记录")
    @DeleteMapping({"/delete/{billId}"})
    public AjaxResult deleteBill(@PathVariable String billId) {
        return toAjax(billService.deleteBillByBillId(billId));
    }
    /**
     * 撤销预约
     *
     * @param billId
     * @return
     */
    @ApiOperation(value = "撤销预约")
    @PutMapping("/quash/{billId}")
    public AjaxResult quashBill(@PathVariable String billId) {
        if(billService.quashBillByBillId(billId)){
            return AjaxResult.success("撤销成功");
        }else {
            return AjaxResult.error("撤销失败");
        }
    }
    /**
     * 退房
     *
     * @param billId
     * @return
     */
    @ApiOperation(value = "退房")
    @PutMapping("/check/{billId}")
    public AjaxResult checkBill(@PathVariable("billId") String billId) {
        return toAjax(billService.checkBillByBillId(billId));
    }
    /**
     * 审核
     *
     * @param billId
     * @return
     */
    @ApiOperation(value = "审核")
    @PutMapping("/apply/{billId}/{status}")
    public AjaxResult applyBill(@PathVariable("billId") String billId,
                                @PathVariable("status") String status) {
        return toAjax(billService.applyBillByBillId(billId, status));
    }
    /**
     * 长期住房申请
     * @return
     */
    @ApiOperation(value = "长期住房申请")
    @PostMapping("/longApply")
    public AjaxResult longApplyBill(@RequestBody Bill bill){
        return toAjax(billService.longApplyBill(bill));
    }
    /**
     *根据用户id查询改用户的所有订单
     */
    @ApiOperation(value = "查询某用户所有订单")
    @GetMapping("/selectTeacherBill/{userId}")
    public AjaxResult selectTeacherBill(@PathVariable("userId") String userId) {
        return AjaxResult.success(billService.selectUserBillList(userId));
    }
}
